package com.adwin.addcoin.repository.db;

import android.content.Context;

import androidx.room.Room;

import java.util.List;

public class RoomUtils {
    private static RoomUtils instance;
    private static Context mContext;
    private RepostRoomDatabase database;

    private String dbName = "adWin_addCoin";

    public synchronized static RoomUtils getInstance(Context context) {
        if (instance == null){
            instance = new RoomUtils();
            mContext = context.getApplicationContext();
            instance.initRoom();
        }
        return instance;
    }

    private void initRoom(){
        database =  Room.databaseBuilder(mContext, RepostRoomDatabase.class,dbName).build();
    }

    public void install(RtRepostData data){
        if (database == null){
            initRoom();
        }
       RtRepost rtRepost = database.getRepost();
        if (rtRepost == null) return;
        rtRepost.insertRt(data);
    }

    public List<RtRepostData> getRePost(int uid){
        RtRepost rtRepost = database.getRepost();
        if (rtRepost == null) return null;
        return rtRepost.getRepost(uid);
    }
 }
